<template>
  <div v-loading="loading">
    <el-table
      :data="tableData"
      style="width: 100%"
      :header-cell-style="styleObj"
      @selection-change="handleSelectionChange"
    >
      <el-table-column v-if="checkbox" type="selection" width="45"></el-table-column>
      <el-table-column v-if="index" type="index" label="序号" width="50" />
      <el-table-column
        v-for="(item,index) in headerList"
        :key="index"
        :prop="item.key"
        :label="item.name"
        :width="item.width"
      >
        <template slot-scope="scope">
          <span v-html="formatter(scope,item.key)"></span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="name" label="申请编号" width="120"></el-table-column>
      <el-table-column prop="province" label="姓名" width="120"></el-table-column>
      <el-table-column prop="city" label="身份证号码" width="120"></el-table-column>
      <el-table-column prop="address" label="通讯地址" width="300"></el-table-column>
      <el-table-column prop="zip" label="手机号码" width="120"></el-table-column>-->
      <el-table-column v-if="btn" fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button
            v-for="(item,index) in btn"
            :key="index"
            @click="()=>$emit(item.way, scope.row)"
            type="text"
            size="medium"
            v-html="item.name"
          ></el-button>
          <el-button
            v-if="scyjbClick && scope.row.zip == 200334"
            @click="()=>$emit('on-scyjbClick', scope.row)"
            type="text"
            size="medium"
          >审查意见表</el-button>
          <!-- <el-button
            @click="()=>$emit('on-lookClick', scope)"
            v-if="btn.indexOf('look')>-1"
            type="text"
            size="medium"
          >查看</el-button>
          <el-button
            @click="()=>$emit('on-editClick', scope.row)"
            v-if="btn.indexOf('edit')>-1"
            type="text"
            size="medium"
          >编辑</el-button>
          <el-button
            @click="()=>$emit('on-sqxqClick', scope.row)"
            v-if="btn.indexOf('sqxq')>-1"
            type="text"
            size="medium"
          >申请详情</el-button>
          <el-button
            @click="()=>$emit('on-shxqClick', scope.row)"
            v-if="btn.indexOf('shxq')>-1"
            type="text"
            size="medium"
          >审核详情</el-button>
          <el-button
            @click="()=>$emit('on-sqtcClick', scope.row)"
            v-if="btn.indexOf('sqtc')>-1"
            type="text"
            size="medium"
          >申请退出</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :hide-on-single-page="true"
        :page-size="10"
        layout="prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
      <!-- :total="tableData.total" -->
    </div>
  </div>
</template>


<script>
export default {
  name: "xTable",
  props: {
    head: Object,
    tableData: Array,
    total: Number,
    btn: Object,
    scyjbClick: Boolean,
    search: Object,
    type: String,
    checkbox: Boolean,
    loading: Boolean,
    index: Boolean,
    fixed: Boolean,
    spanMethod: Boolean
  },
  data() {
    return {
      styleObj: {
        background: "rgba(245,247,250,1)"
      },
      headerList: [],
      currentPage: 1,
      multipleSelection: []
    };
  },
  watch: {
    search(val) {
      this.currentPage = val.current;
    }
  },
  methods: {
    handleCurrentChange(val) {
      this.search.page = this.currentPage;
      this.search.size = "10";
      this.$emit("on-changePage", this.search);
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.$emit("on-SelectionChange", this.multipleSelection);
    },
    formatter: function(scope, key) {
      if (key === "zip") {
        return this.zip(scope.row[key]);
      } else {
        return scope.row[key] || "--";
      }
    },
    zip: function(item) {
      if (item == "200333") {
        return "<span style='color:#00aa28;'>男</span>";
      }
      if (item == "200334") {
        return "<span style='color:#ff4a03;'>女</span>";
      }
    }
  },
  mounted() {
    for (var key in this.head) {
      var item = this.head[key];
      var name = item.name || this.head[key],
        width = item.width || "";
      this.headerList.push({ name: name, key: key, width: width });
    }
  }
};
</script>

<style lang="scss" scoped>
.block {
  float: right;
  margin: 30px;
}
</style>
